package com.example.springboottest.example.serialize;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Optional;

public class SerializeTest {

    public static void main(String[] args) throws Exception {
//        File file = new File("/Users/fangdaye/Downloads/SerializeTest/JavaSerialize.txt");
//        writeFileByJava(file);
//        readFileByJava(file);



//        File file2 = new File("/Users/fangdaye/Downloads/SerializeTest/JavaSerialize2.txt");
//        writeFileByJava2(file2);

//        AvroSerialize.handleSerialize();
//        AvroSerialize.handleDeSerialize();
    }

    public static void writeFileByJava(File file) throws IOException {
        FileOutputStream outputStream = new FileOutputStream(file);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(new JavaSerialize("wang", "guangzhou", 2, 1000, 19));
        objectOutputStream.close();
    }


    public static void readFileByJava(File file) throws Exception {
        FileInputStream inputStream = new FileInputStream(file);
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        JavaSerialize javaSerialize = (JavaSerialize) objectInputStream.readObject();
        System.out.println(javaSerialize.toString());
        objectInputStream.close();
    }


    public static void writeFileByJava2(File file) throws IOException {
        FileOutputStream outputStream = new FileOutputStream(file);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        Optional<String> name = Optional.of("wang");
        objectOutputStream.writeObject(new JavaOptionalSerialize(name, "guangzhou", 2, 1000, 19));
        objectOutputStream.close();
    }
}